var $=KISSY.all;
var wheels; 
if(KISSY.UA.shell=="ie"){
	$(".action_flash_wheel").removeClass("hide");
	$(".action_egg").css("background","#FFF");
	$(".wheels_ac").css("background-image","none");
	$(".action_egg").css("-moz-opacity",0);
	$(".action_egg").css("opacity",0);
	$(".action_egg").css("filter","alpha(opacity=0)");
}else{
	wheel(10000,100);
}
// http://cart.taobao.com/json/asyncGetMyCart.do?callback=jsonpCallback1

var top_sign = $(".sign").val();
var sid = $(".sid").val();
var usernick="";
var top="";
var ti = new Date().getTime();
var shoucang = 0;
function cartadd(){
	// var myDate=new Date();
	// if(myDate.getMonth()==10&&myDate.getDate()==11){
		// alert("抱歉，双十一期间不可以使用购物车抽奖，请努力下单吧！");
		// return ; 
	// }
	var items = $(".cart_items").val();
	items=items.split(",");
	var pics = $(".cart_items_pics").val();
	pics=pics.split(",");
	var html = "";
	for(var i=0;i<items.length;i++){
		html+='<li><img alt="" src="'+pics[i]+'_100x100.jpg"/><br /><a href="https://item.taobao.com/item.htm?id='+items[i]+'" class="btn btn-mini btn-info js-cartitem" data-iid="'+items[i]+'">加购物车</a></li>';
	}
	$(".ks-stdmod-header").text("收藏抽奖：请在打开的页面中添加购物车");
	$(".ks-switchable-content").empty();
	$(html).prependTo(".ks-switchable-content");
	$(".js-cartitem").on("click",function(){
		var item = $(this).attr("data-iid");
		cartajax(item);
	});
	$(".ks-dialog").removeClass("hide");
	$(".j-default").fire("mouseover");
	$(".js-close").on("click",function(){$(".js-jifenduih").addClass("hide")});
}
function cartajax(itemstr){
	var sign = R(sid+"|"+itemstr+"|"+usernick+"|"+top_sign+"|"+"ntPfLBg"+ti);
	var data = {"shop_id":sid,"usernick":usernick,"sign":sign,"top_sign":top_sign,"itemstr":itemstr,"ts":ti};
	var url = "/?a=addcart&c=user&m=Shopmodule";
	KISSY.io({
		"url": url,
		"data":data,
		"success": function(data, textStatus) {
			
		},
		"error": function(){
			
		},
		"dataType":"jsonp"
	});
}
function closeDialog(){
$(".bui-ext-close-x").fire("click");
$(".js-close").fire("click");
}
$(".js-suoqu").on("click",function(){
	var fuid = $(this).attr("data-fuid");
	suoqu(fuid);
});
$(".js-zengsong").on("click",function(){
	var fuid = $(this).attr("data-fuid");
	suoqu(fuid,"zengsong");
});
function duihuan(){
	var sign = R(sid+"|"+usernick+"|"+top_sign+"|"+"ntPfLBg"+ti);
	KISSY.io({
		url: "/?a=read_dhjp&m=shopmodule&c=jifen",
		data: {"usernick":usernick,"sid":sid,"sign":sign,"top_sign":top_sign,"ti":ti},
		success: function(data, textStatus) {
			closeDialog();
			if(data.status==false){
				gameDialog("兑换失败",data.msg,"event");
			}
			var html = "";
				for(var i=0;i<data.duihuan.length;i++){
					html+='<li><span>（'+data.duihuan[i].jifen+'积分）</span><img alt="" src="'+data.duihuan[i].gift_pic_url+'_100x100.jpg"/>'+data.duihuan[i].gift_name+'<br /><input class="btn btn-mini btn-info js-giftdh" data-gid="'+data.duihuan[i].gift+'" type="button" value="立即兑换"></li>';
				}
				$(".ks-switchable-content").empty();
				$(html).prependTo(".ks-switchable-content");
				$(".ks-stdmod-header").text("积分兑换奖品");
				$(".js-giftdh").on("click",function(){
					var gid = $(this).attr("data-gid");
					KISSY.io({
						url: "/?a=duihuan&m=shopmodule&c=jifen",
						data: {"usernick":usernick,"sid":sid,"gid":gid,"sign":sign,"top_sign":top_sign,"ti":ti},
						success: function(data, textStatus) {
							// closeDialog();
							if(data.status==false){
								gameDialog("兑换失败",""+data.msg,"event");
							}else{
								gameDialog("兑换成功",""+data.msg,"event");
							}
						},
						complete: function(data){
							
						},
						error: function(){
							alert('出错啦！请仔细检查一下输入的数据是否有误！');
						},
						dataType:"jsonp"
					});
				});
				$(".js-jifenduih").removeClass("hide");
				$(".j-default").fire("mouseover");
				$(".js-close").on("click",function(){$(".js-jifenduih").addClass("hide")});
			// gameDialog("积分兑换奖品","请选择要兑换的奖品","event");
			
		},
		complete: function(data){
			
		},
		error: function(){
			alert('出错啦！请仔细检查一下输入的数据是否有误！');
		},
		dataType:"jsonp"
	});
}
function qiandao(){
		var sign = R(sid+"|"+usernick+"|"+top_sign+"|"+"ntPfLBg"+ti);
		KISSY.io({
		url: "/?a=qiandao&m=shopmodule&c=jifen",
		data: {"usernick":usernick,"sid":sid,"sign":sign,"top_sign":top_sign,"ti":ti},
		success: function(data, textStatus) {
			closeDialog();
			if(data.login==false){
				gameDialog("签到失败","签到不成功，请重新打开店铺签到","event");
				$(".bui-stdmod-body").css("text-align","center");
				$(".J_TB_Login").clone(true,true,true).appendTo(".bui-stdmod-body").removeClass("hide");
			}else{
				gameDialog("签到",data.msg,"event");
				$(".js-ok").remove();
				$(".js-dhdh").on("click",function(){
					$(".js-ddhjiafen").fire("click");
				});
				$(".js-calqd").text("已签");
			}
		},
		complete: function(data){
			
		},
		error: function(){
			alert('出错啦！请仔细检查一下输入的数据是否有误！');
		},
		dataType:"jsonp"
	});
}
// $(".buyer").on("mouseout",function(){
	// $(".refresh").hide();
// });
$(".buyer").on("mouseenter",function(){
	$(".refresh").show();
});
$(".gg,.gz,.dj").on("click",function(){
	var tp = $(this).attr("data-tp");
	var sid = $(".sid").val();
	switch(tp){
		case "gg" : var t = "活动公告";break;
		case "gz" : var t = "游戏规则";break;
		case "dj" : var t = "兑奖方式";break;
	}
	KISSY.io({
		url: "/?a=getgg&m=shopmodule",
		data:{"tp":tp,"sid":sid},
		success: function(data, textStatus) {
			closeDialog();
			gameDialog(t,"<span style=\"font-size:12px\">"+data.msg+"</span>","event");
		},
		error: function(){
			alert('出错啦！请仔细检查一下输入的数据是否有误！');
		},
		dataType:"jsonp"
	});
});
var usrpg=0;
$(".js-showicon").on("mouseenter mouseout",function(e){
	var togid = $(this).attr("data-id");
	if(e.type=="mouseenter"){
	$("."+togid).removeClass("hide");
	}else{
	$("."+togid).addClass("hide");
	}
	
});
$(".refresh").on("click",function(){
	KISSY.io({
		url: "/?a=rfrusers&m=front&c=event",
		data:{"pg":usrpg},
		success: function(data, textStatus) {
			closeDialog();
			if(data.status==false){
				alert("已经没有更多用户了！");
				return;
			}
			var usr="";
			for(var i=0;i<data.length;i++){
				usr+=("<div class=\"buyer\">");
				usr+=("        <div class=\"avatar\">");
				usr+=("                    <p><img src=\""+data[i].avatar+"\"></p>");
				usr+=("                    <a class=\"suo js-suoqu\" data-fuid=\""+data[i].id+"\"><img src=\"http://img04.taobaocdn.com/imgextra/i4/27390555/TB2ouFfaXXXXXbYXpXXXXXXXXXX_!!27390555.jpg\"></a>");
				usr+=("                </div>");
				usr+=("                <div class=\"stat\">");
				usr+=("                    <p>抽奖次数：<span>"+data[i].lotts+"次</span></p>");
				usr+=("                    <p>中奖次数：<span>"+data[i].wins+"次</span></p>");
				usr+=("                    <p>中奖率：<span>"+data[i].val+"/100</span></p>");
				usr+=("                    ");
				usr+=("                    <a href=\"/?m=front&c=event#\"><img src=\"http://img04.taobaocdn.com/imgextra/i4/27390555/TB2vuhfaXXXXXX4XpXXXXXXXXXX_!!27390555.jpg\" style=\"border:0px;\"></a>");
				usr+=("                </div>");
				usr+=("    </div>");
			}
			$(".buyer").remove();
			$(usr).appendTo(".buyers");
			$(".js-suoqu").on("click",function(){
				var fuid = $(this).attr("data-fuid");
				suoqu(fuid);
			});
			usrpg++;
		},
		error: function(){
			alert('出错啦！请仔细检查一下输入的数据是否有误！');
		},
		dataType:"jsonp"
	});
});
function suoqu(fuid,action){
if(!action){
	action="suoqu";
}
KISSY.io({
	url: "/?a="+action+"&m=front&c=index",
	data: {"fuid":fuid},
	success: function(data, textStatus) {
		closeDialog();
		if(data.login==false){
			gameDialog("尚未登录","您尚未登录，请登录后继续！<br />","buyers");
			$(".bui-stdmod-body").css("text-align","center");
			$(".J_TB_Login").clone(true,true,true).appendTo(".bui-stdmod-body").removeClass("hide");
		}else{
			alert(data.msg);
		}
	},
	complete: function(data){
		
	},
	error: function(){
		alert('出错啦！请仔细检查一下输入的数据是否有误！');
	},
	dataType:"jsonp"
});
}
var clicktp;
// 加入购物车：
// TOP.ui("sku", {
	// container:".top-widget-sku",
	// text:"加入购物车",
	// itemId:"39869678494",
	// type:"",
	// callback:{
		// addCartSuccess:function(e){console && console.log(e);},
		// error:function(e){console && console.log(e);}
// }
// });
// // 登录按钮：
// TOP.ui("login-btn", {
	// container:".top-login-btn-container",
	// type:"1,1",
	// callback:{
		// login:function(user){alert(user)},
		// logout:function(){}
	// }
// });
function ddhjiafen(){
	closeDialog();
	gameDialog("订单兑换积分","请输入订单号：<input type=\"text\" class=\"orderid\" style=\"width:200px\"  /> <button class=\"btn btn-mini btn-info js-dddhjf\">确定</button>","event");
	$(".js-ok").remove();
	$(".js-dddhjf").on("click",function(){
		var oid = ($(".orderid").val());
		var sign = R(sid+"|"+oid+"|"+usernick+"|"+"ntPfLBg"+ti);
		KISSY.io({
			url: "/?a=dddhjf&m=shopmodule&c=Jifen",
			type:"POST",
			data: {"oid":oid,"usernick":usernick,"sid":sid,"sign":sign,"ti":ti},
			success: function(data, textStatus) {
				closeDialog();
				if(data.login==false){
					gameDialog("失败信息",data.msg,"event");
				}else{
					gameDialog("尚未登录",data.msg,"event");
				}
			},
			error: function(){
				alert('出错啦！请仔细检查一下输入的数据是否有误！');
			},
			dataType:"jsonp"
		});
	});
}
function jfjiacheng(){
	KISSY.io({
		url: "/?a=jfjc&m=shopmodule&c=Jifen",
		type:"POST",
		data: {"usernick":usernick,"sid":sid},
		success: function(data, textStatus) {
			closeDialog();
			gameDialog("签到加成",data.msg,"event");
			$(".js-dhdh").on("click",function(){
				$(".js-ddhjiafen").fire("click");
			});
			$(".js-ok").remove();
		},
		error: function(){
			alert('出错啦！请仔细检查一下输入的数据是否有误！');
		},
		dataType:"jsonp"
	});
}
TOP.ui("authbtn", {
     type:'mini',
     onload:function(handler){ 
		$(".dolott,.action,.gua").on("click",function(e){
			// var mygift = $(e.currentTarget).hasClass("mygift");
			clicktp="dolott";
			if(!usernick){
				handler();
			}else{
				dolott();
			}
		});
		$(".mygift,.js-cart,.js-qiandao,.js-jfduihuan,.js-ddhjiafen,.js-duihuan,.js-qdduihuan,.js-jfjiacheng").on("click",function(){
			clicktp=$(this).attr("data-tp");
			if(!usernick){
				handler();
			}else{
				switch(clicktp){
					case "gft":showmygift();break;
					case "dolott":dolott();break;
					case "cart":cartadd();break;
					case "qiandao":qiandao();break;
					case "duihuan":duihuan();break;
					case "qdduihuan": qiandaorili(); break;
					case "jfjiacheng": jfjiacheng(); break;
					case "ddhjiafen": ddhjiafen(); break;
				}
			}
		});
     },
     callback: function(data){ 
		if(data.success==true){
			usernick = (data.result.taobao_user_nick); 
			switch(clicktp){
				case "gft":showmygift();break;
				case "dolott":dolott();break;
				case "cart":cartadd();break;
				case "qiandao":qiandao();break;
				case "duihuan":duihuan();break;
				case "qdduihuan": qiandaorili(); break;
				case "jfjiacheng": jfjiacheng(); break;
				case "ddhjiafen": ddhjiafen(); break;
			}
		}else{
			gameDialog("尚未登录","<center>您尚未登录淘宝，请<a target=\"_blank\" class=\"btn btn-mini btn-warning js-cls \" href=\"http://trade.taobao.com/trade/itemlist/list_bought_items.htm\">登录</a>后继续！</center>","event");
			$(".js-cls").on("click",function(){closeDialog();});
			$(".js-ok").remove();
		}
	 }
});
function __dialog(title,msg,show,button,width,top){
width=width?width:($("."+show).innerWidth())/2; 
var margin=(990-width)/2;
top=top?top:100;
var tstr = top?"top:"+top+"px;":"";
var wstr = width?"width:"+width+"px;":"width:830px";
// var mask = ("<div style=\"width:100%;left:0;top:0;height:100%;position:fixed;\" class=\"bui-ext-mask\"></div>");
// $(mask).insertBefore("."+show);
var temp = '';
temp+='<div class="js-mydlg js-gmdlg ks-dialog ks-overlay allow_over" style="'+wstr+'margin-left:'+margin+'px;margin-right:'+margin+'px;left:0;visibility:visible;z-index:9;display:block;'+tstr+'">';
temp+='	<div class="ks-contentbox" style="height:auto">';
temp+='		<div class="ks-stdmod-header" style="text-align:left">'+title+'</div>';
temp+='		<div class="ks-stdmod-body" style=\"margin:10px\">';
temp+='			<div class="con-als" style=\"margin:10px\">';
temp+='			'+msg;
temp+='			</div>';
temp+='			<div style="text-align:center;margin:10px 20px 60px 20px">'+button+'</div>';
temp+='		</div>';
temp+='		<div class="ks-stdmod-footer"></div>';
temp+='	</div>';
temp+='	<a class="ks-ext-close" role="button" href="javascript:void(" 关闭")"="" tabindex="0">';
temp+='		<span class="ks-ext-close-x js-close js-mycls">关闭</span>';
temp+='	</a>';
temp+='</div>';
$(temp).appendTo("."+show);
$(".js-mycls,.btn-warning").on("click",function(){
	$(".js-mydlg").remove();
});
}
function gameDialog(title,msg,show,oid,width,top){
// var top=($("."+show).outerHeight())/2;
width=width?width:($("."+show).innerWidth())/2; 
var margin=(990-width)/2;
top=top?top:100;
var tstr = top?"top:"+top+"px;":"";
var wstr = width?"width:"+width+"px;":"width:830px";
// var mask = ("<div style=\"width:100%;left:0;top:0;height:100%;position:fixed;\" class=\"bui-ext-mask\"></div>");
// $(mask).insertBefore("."+show);
var temp = '';
temp+='<div class="js-gmdlg ks-dialog ks-overlay allow_over" style="'+wstr+'margin-left:'+margin+'px;margin-right:'+margin+'px;left:0;visibility:visible;z-index:9;display:block;'+tstr+'">';
temp+='	<div class="ks-contentbox" style="height:auto">';
temp+='		<div class="ks-stdmod-header" style="text-align:left">'+title+'</div>';
temp+='		<div class="ks-stdmod-body"  style=\"margin:10px\">';
temp+='			<div class="con-als" style=\"margin:10px\">';
temp+='			'+msg;
temp+='			</div>';
if(oid){
temp+='			<div style="text-align:center"><input class="btn btn-mini btn-info js-dolott" type="button" value="继续抽"><input class="btn btn-mini btn-info js-ok" type="button" value="知道了"></div>';
}else{
temp+='			<div style="text-align:center"><input class="btn btn-mini btn-info js-ok" type="button" value="知道了"></div>';
}
temp+='		</div>';
temp+='		<div class="ks-stdmod-footer"></div>';
temp+='	</div>';
temp+='	<a class="ks-ext-close" role="button" href="javascript:void(" 关闭")"="" tabindex="0">';
temp+='		<span class="ks-ext-close-x js-close">关闭</span>';
temp+='	</a>';
temp+='</div>';
$(temp).appendTo("."+show);
$(".js-close,.js-ok").on("click",function(){
	$(".js-gmdlg").remove();
});
$(".js-dolott").on("click",function(){
	var oid = $(".oid").val();
	dolott(oid);
});
$(".js-dolott-ready").on("click",function(){
	var oid = $(this).attr("data-oid");
	dolott(oid,true);
});

}
function dolott(oid,readoid){
	$(".js-gmdlg").remove();
	oid = oid?oid:"";
	var tool_type = $(".tool_type").val();
	var ddcj = $(".ddcj").val();
	var none_anim = $(".none_anim").val();
	var sign,data,url;
	if(tool_type==1||tool_type==9){
		sign = R(sid+"|"+oid+"|"+usernick+"|"+top_sign+"|"+"ntPfLBg"+ti);
		data = {"shop_id":sid,"usernick":usernick,"sign":sign,"top_sign":top_sign,"oid":oid,"ts":ti,"rd":readoid};
		url = "/?a=normallot&m=Shopmodule";
	}
	if(tool_type==3||tool_type==8){
		sign = R(sid+"|"+oid+"|"+usernick+"|"+lastscoreid+"|"+lastrange+"|"+lotts+"ntPfLBg"+ti);
		data = {"shop_id":sid,"usernick":usernick,"lastscoreid":lastscoreid,"lotts":lotts,"lastrange":lastrange,"sign":sign,"top_sign":top_sign,"oid":oid,"ts":ti,"rd":readoid};
		url = "/?a=dolotts&m=Shopmodule";
	}
	
	KISSY.io({
		"url": url,	
		"data":data,
		"success": function(data, textStatus) {
			closeDialog();
			if(data.status==true){
				var t = "中奖啦！亲，多次中同样的奖只发一次奖品哦！";
				top = 50;
			}else{
				var t = "抱歉，您没中奖";
				top=100;
			}
			var gift = "";
			var msg="";
			var style="width:300px;margin-top:15px;margin-left:auto;margin-bottom:10px;margin-right:auto; text-align: center";
			if(data.status==false&&data.score==0&&ddcj){
				msg = "您还可以输入订单号抽奖！多买多抽哦，亲~<br />订单号：<input type=\"text\" class=\"oid\" />";
				style="margin-top:25px;margin-left:40px;text-align:left";
				var oid = true;
			}
			if(data.status==true){
				gift = "<a href=\""+data.withdraw+"\"><img src=\""+data.giftpic+"_160x160.jpg\" /></a>";
				if(data.type==4){
					gift += "<br />卡号："+data.cardno+"";
					gift += "<br />密码："+data.secret+"";
				}
			}
			if(data.status=="mission"){
				var mis = data.mission;
				var mission = mis.split(",");
				if(mission.length==2){
				style="width:300px;margin-top:15px;margin-left:auto;margin-bottom:10px;margin-right:auto; text-align: center";
				}
				if(mission.length==1){
				style="width:150px;margin-top:15px;margin-left:auto;margin-bottom:10px;margin-right:auto; text-align: center";
				}
				for(var i=0;i<mission.length;i++){
					switch(mission[i]){
						case "followshop":
						// 收藏店铺抽奖
							msg = "<div style=\"width:150px;height:100px;float:left\">亲，请先收藏店铺哦！<br /><div  class=\"js-scsc js-collect\" style=\"background:url(http://img03.taobaocdn.com/imgextra/i3/27390555/TB2WAVabpXXXXb6XXXXXXXXXXXX-27390555.gif); height:60px;width:75px;margin:auto\"></div><div class=\"js-scok\" style=\"cursor:pointer;background:url(http://img03.taobaocdn.com/imgextra/i3/27390555/TB2WAVabpXXXXb6XXXXXXXXXXXX-27390555.gif) -225px -19px ; height:22px;width:75px;margin:auto;color:#FFF\">　请先收藏</div></div>"
						break;
						case "brandid":
						// 关注品牌抽奖
							msg += "<div style=\"width:150px;height:100px;float:left\">亲，请先关注本店品牌<div class=\"js-brand\" style=\"background:url(http://img03.taobaocdn.com/imgextra/i3/27390555/TB2WAVabpXXXXb6XXXXXXXXXXXX-27390555.gif) -75px 0; height:60px;width:75px;margin:auto\"></div><div  class=\"js-brandtxt\" style=\"background:url(http://img03.taobaocdn.com/imgextra/i3/27390555/TB2WAVabpXXXXb6XXXXXXXXXXXX-27390555.gif) -150px -19px ; height:22px;width:75px;margin:auto;color:#FFF;cursor:pointer\">　请先关注<\/div></div>"
						break;
					}
				}
				gameDialog(t,"<div style=\""+style+"\">"+data.giftname+"<br />"+msg+"<br style=\"clear:both\" /></div>","event",oid,false,top);
				$(".js-collect,.js-scok").on("click",function(){
					__dialog("提示","<div class=\"js-plsscmsg\" style=\"width:300px;margin-top:40px;margin-left:auto;margin-right:auto; text-align: center\">亲，快收藏我吧！</div>","event","<a class=\"js-plscl btn btn-success\" target=\"_blank\" href=\"http://favorite.taobao.com/popup/add_collection.htm?id="+$(".sid").val()+"&itemid="+$(".sid").val()+"&itemtype=0&sellerid="+$(".uid").val()+"&scjjc=2\" >收藏</a><br /><button class=\"btn btn-danger hide js-plssc\" type=\"button\">已经收藏过啦！</button><br />","","50");
					$(".js-plscl").on("click",function(){
						if(shoucang>=2){
							KISSY.io({
								"url":"/?a=collect&m=Shopmodule&c=User",	
								"data":{"usernick":usernick,"sid":sid},
								"success": function(data, textStatus){
									// $(".js-scsc").html("已经收藏");
									
									$(".js-scsc").remove();
									$(".js-scok").html("　已经收藏");
									$(".js-scok").detach("click");
									$(".js-mydlg").remove();
								},
								"error": function(){
									alert('出错啦！请仔细检查一下输入的数据是否有误！');
								},
								//发送请求类型是jsonp
								"dataType":"jsonp"
							});	
						}
						shoucang++;
						$(".js-plsscmsg").html("亲，您收藏过了吗？");
						$(".js-plssc").removeClass("hide");
						$(this).remove();
					});
					$(".js-plssc").on("click",function(){
						KISSY.io({
							"url":"/?a=collect&m=Shopmodule&c=User",	
							"data":{"usernick":usernick,"sid":sid},
							"success": function(data, textStatus){
								// $(".js-scsc").html("已经收藏");
								
								$(".js-scsc").remove();
								$(".js-scok").html("　已经收藏");
								$(".js-scok").detach("click");
								$(".js-mydlg").remove();
							},
							"error": function(){
								alert('出错啦！请仔细检查一下输入的数据是否有误！');
							},
							//发送请求类型是jsonp
							"dataType":"jsonp"
						});	
					});	
				});
				$(".js-brand,.js-brandtxt").on("click",function(){
					// 关注品牌按钮
					var brandid = $(".brandid").val();
					var msg = "<div style=\"width:150px;height:100px;float:left\">亲，在店铺里找到这个：<a href=\"http://mybrand.tmall.com/brandInfo.html?brandId="+brandid+"\" target=\"_blank\"><div style=\"background:url(http://img03.taobaocdn.com/imgextra/i3/27390555/TB2WAVabpXXXXb6XXXXXXXXXXXX-27390555.gif) -150px -19px ; height:22px;width:75px;margin:20px auto;color:#FFF;cursor:pointer\">　关注</div></a></div>";
						msg+= "<div style=\"width:150px;height:100px;float:left\">让它变成这样：<a href=\"http://mybrand.tmall.com/brandInfo.html?brandId="+brandid+"\" target=\"_blank\"><div style=\"background:url(http://img03.taobaocdn.com/imgextra/i3/27390555/TB2WAVabpXXXXb6XXXXXXXXXXXX-27390555.gif) 75px -19px ; height:22px;width:75px;margin:20px auto;color:#FFF;cursor:pointer\">　</div></a></div>";
						msg+= "<button class=\"btn btn-success js-brandok\" type=\"button\">我搞定啦！</button>";
					__dialog("提示","<div style=\"width:300px;height:200px;margin-top:40px;margin-left:auto;margin-right:auto; text-align: center\">"+msg+"</div>","event","","","50");
					$(".js-brandok").on("click",function(){
						KISSY.io({
							data:{"brandId":brandid},
							url: "http://brand.tmall.com/ajax/getBrandStatusBatch.htm",
							success: function(data, textStatus) {
								if(!data.errorCode){
									if((data.result[0].isMyBrand)==1){
										KISSY.io({
											"data":{"usernick":usernick,"brandid":brandid},
											"url":"/?a=brandme&m=Shopmodule&c=User",
											"success": function(data, textStatus) {
												$(".js-brand").remove();
												$(".js-mydlg").remove();
												$(".js-brandtxt").html("　已经关注");
											},
											"error": function(){
												alert('关注失败，请重试');
											},
											"dataType":"jsonp"
										});
										
									}else{
										alert("没有关注成功！您必须关注本店品牌才可以抽奖");
									}
								}else{
									alert(data.errorCode+"品牌id不存在！请仔细检查您的品牌ID");
								}
							},
							complete: function(data){
								
							},
							error: function(){
								alert('出错啦！请仔细检查一下输入的数据是否有误！');
							},
							dataType:"jsonp"
						});
					});
				});
				// $(".js-ok").val("已完成任务！");
			}else{
				if(tool_type==3 || (data.status==false && none_anim==0 && data.score==0)){
					gameDialog(t,"<div style=\""+style+"\">"+data.giftname+"<br />"+gift+msg+"<br style=\"clear:both\" /></div>","event",oid,false,top);
				}else{
					doanim(data,t,"<div style=\""+style+"\">"+data.giftname+"<br />"+gift+msg+"<br style=\"clear:both\" /></div>","event",oid);
				}
			}
		},
		"error": function(){
			alert('出错啦！请仔细检查一下输入的数据是否有误！');
		},
		//发送请求类型是jsonp
		"dataType":"jsonp"
	});
}
$(".sns-like").on("click",function(){
mission("likeme",$(this).attr("data-eid"));
});
$(".sns-followshop").on("click",function(){
mission("collect",$(this).attr("data-eid"));
});
$(".sns-friendfollow").on("click",function(){
mission("followme",$(this).attr("data-eid"));
});
$(".sns-sharebtn").on("click",function(){
mission("shareme",$(this).attr("data-eid"));
});

function mission(mis,eid){
	KISSY.io({
		url: "/?a=mission&m=front&c=event",
		data: {"mis":mis,"eid":eid},
		success: function(data, textStatus) {
		closeDialog();
			if(data.status==false){
				gameDialog("出错","完成任务出错。","event");
			}else{
				//gameDialog("成功！","恭喜您完成任务！","event");
			}
		},
		complete: function(data){
			
		},
		error: function(){
			alert('出错啦！请仔细检查一下输入的数据是否有误！');
		},
		dataType:"jsonp"
	});
}
function getgift(data){
	if(data.status==true && data.level=="5"){
		var gft = "中奖";
		return gft;
	}
		switch(data.level){
			case "1" : var gft = "一等奖"; break;
			case "2" : var gft = "二等奖"; break;
			case "3" : var gft = "三等奖"; break;
			case "4" : var gft = "鼓励奖"; break;
			default : 
				var gt = ["大奖在即！","再接再厉","大奖不远啦！","亲，加油！","谢谢参与"];
				var gft =gt[parseInt(4*Math.random())];
			break;
		}
		return gft;
}
$(".dicesdiv").css("-moz-opacity",0);
$(".dicesdiv").css("opacity",0);
$(".dicesdiv").css("filter","alpha(opacity=0)");
function doanim(data,t,msg,selec,oid){
	var curtool = $(".curtool").val();
	//水果机的动画
	if(curtool=="fruit"){
		gameDialog(t,msg,selec,oid,false,top);
	}
	//随机六边形的动画
	if(curtool=="chest"){
		// if(data.score>0){
			$(".chest_ac").hide();
			$(".js-t").remove();
			var gft = getgift(data);
			if(itv){clearInterval(itv);}
			var last_chest;
			var ts=0;
			var itv = setInterval(function (){
				if(last_chest){$(".chest"+last_chest).hide();}
				var i = parseInt(9*Math.random()+1);
				$(".chest"+i).show();
				last_chest=i;
				if(ts>=2000){
				clearInterval(itv);
					if(data.status==true){
						var t = "奖品藏在这";
					}else{
						var t = "天气真好";
					}
					$(".chest_ac ").html("<div class=\"js-t\" style=\"font-size:12px;color:#FF3A3A;margin-top:48px;text-align: center;\">"+gft+"</div>");
					$(".chest_ac ").on("click",function(){
					gameDialog(t,msg,selec,oid,false,top);
					});
				}
				ts+=30;
			},30);
		// }else{
			// gameDialog(t,msg,selec,oid);
		// }
	}
	//刮刮卡的动画
	if(curtool=="scratchcards"){
		// if(data.score>0){
		var gft = getgift(data);
		$(".g").remove();
		var g = '<div class="g" style="position:absolute;top: 205px;width:174px;text-align:center;z-index:0">'+gft+'</div>';
		$(g).insertAfter(".gua");
			// KISSY.use("anim", function(S, Anim){
				var b = new KISSY.Anim('.gua',{"width": 0}, 1 ,'',function(){gameDialog(t,msg,selec,oid,false,top);});
				b.run();
			// });
		// }else{
			// gameDialog(t,msg,selec,oid);
		// }
	}
	//大富翁的动画
	if(curtool=="dices"){
		var num = $(".fcount").val();
		var giftset=new Array();
		var itv=false;
		for(var i=1;i<=num;i++){
			$(".dd"+i).css("-moz-opacity",0);
			$(".dd"+i).css("opacity",0);
			$(".dd"+i).css("filter","alpha(opacity=0)");
			giftset[i]=$(".dd"+i).attr("data-gft");
		}
		if(itv){clearInterval(itv);}
		// if(data.score>0){
			var row = parseInt(3*Math.random()+1);
			var gift=0;
			if(data.status==false||data.gid==0){
				data.gid=0;
			}
			var s = new Array();
			for(var i=1;i<=giftset.length;i++){
				if(giftset[i]==data.gid){
					s.push(i);
				}
			}
			gift=s[parseInt(s.length*Math.random())];
			var alp = 100;
			var dd = 1;
			var ts = 0;
			var ad = num;
			var rowcont = 0;
			itv = setInterval(function (){
				var ddadd =[0,1,2,3,4];
				if(dd<6){
					for(var i=0;i<ddadd.length;i++){
						$(".dd"+(ad-ddadd[i])).css("-moz-opacity",1-(0.2*(i+1)));
						$(".dd"+(ad-ddadd[i])).css("opacity",1-(0.2*(i+1)));
						$(".dd"+(ad-ddadd[i])).css("filter","alpha(opacity="+100-(20*(i+1))+")");
					}
					ad ++;
				}
				for(var i=0;i<ddadd.length;i++){
					$(".dd"+(dd-ddadd[i])).css("-moz-opacity",1-(0.2*(i+1)));
					$(".dd"+(dd-ddadd[i])).css("opacity",1-(0.2*(i+1)));
					$(".dd"+(dd-ddadd[i])).css("filter","alpha(opacity="+100-(20*(i+1))+")");
				}
				dd++;
				if(dd>num){
					dd=1;
					ad=num;
					rowcont++;
				}
				// $(".gonggao").html(row+"|"+rowcont+"|"+dd+"|"+gift);
				if(dd==gift&&row<=rowcont){
					for(var i=1;i<=num;i++){
						if(i==gift){
							$(".dd"+i).css("-moz-opacity",0.8);
							$(".dd"+i).css("opacity",0.8);
							$(".dd"+i).css("filter","alpha(opacity=80)");
						}else{
							$(".dd"+i).css("-moz-opacity",0);
							$(".dd"+i).css("opacity",0);
							$(".dd"+i).css("filter","alpha(opacity=0)");
						}
					}
					dd=1;
					clearInterval(itv);
					gameDialog(t,msg,selec,oid,false,top);
				}
				if(rowcont>3){
					dd=1;
					clearInterval(itv);
					gameDialog(t,msg,selec,oid,false,top);
					for(var i=1;i<=num;i++){
						$(".dd"+i).css("-moz-opacity",0);
						$(".dd"+i).css("opacity",0);
						$(".dd"+i).css("filter","alpha(opacity=0)");
					}
				}
				ts += 30;
			},60);
		// }else{
			// gameDialog(t,msg,selec,oid);
		// }
	}
	//砸金蛋的动画
	if(curtool=="eggs"){
		$(".eggs_ac").css("background-position","-209px 0");
		for(var i=1;i<=12;i++){
			$(".jh"+i).css("visibility","visible");
			var x = parseInt(240*Math.random());
			if(i%2==0){var lft=true;}else{var lft=false;}
			pwx($(".jh"+i).getDOMNode(),x,1,lft);
		}
		setTimeout(function(){
			gameDialog(t,msg,selec,oid,false,top);
			$(".js-ok,.js-close,.js-dolott").on("click",function(){
				$(".eggs_ac").css("background-position","");
				for(var i=1;i<=12;i++){
					$(".jh"+i).css("left","460px");
					$(".jh"+i).css("top","300px");
					$(".jh"+i).css("visibility","hidden");
				}
			});
		},2000);

	}
	//大转盘的动画
	if(curtool=="wheels"){
		var on = new Array();
		if(data.score==0){
			gameDialog(t,msg,selec,oid,false,top);
			return;
		}
		if($(".jpbangding").val()==1){
			if(data.status==true){
				var start = $(".gift"+data.gid).attr("data-startdg");
				var end  = $(".gift"+data.gid).attr("data-enddg");
			}else{
				var nonegifts = $(".gift0").getDOMNodes();
				var stopgift = RandomNum(0,nonegifts.length);
				var start = $(nonegifts[stopgift]).attr("data-startdg");
				var end = $(nonegifts[stopgift]).attr("data-enddg");
			}
			var stop = RandomNum(start,end);
				stop += 360*RandomNum(2,4);
				wheel(stop,2,t,msg,selec,oid,data.gid);
		}else{
			if(data.status==true){
				switch(data.level){
					case "1" :
					on.push(0);
					break;
					case "2" :
					on.push(-90);
					break;
					case "3" :
					on.push(180);
					break;
					case "4" :
					on.push(135);
					break;
					default:
					on.push(45);
					break;
				}
				wheel(on[0]+360*RandomNum(2,4),2,t,msg,selec,oid,data.gid);
			}else{
				on.push(-45);
				on.push(90);
				on.push(225);
				wheel(on[RandomNum(0,2)]+360*RandomNum(2,4),2,t,msg,selec,oid,data.gid);
			}
		}
	}
}
function pwx(rect,radian,step,lft){
            var animate = function(opt){
                var cos = Math.cos(opt.radian*Math.PI/180);//邻边比斜边,60度的话等于1/2
                var sin = Math.sin(opt.radian*Math.PI/180);//对边比斜边,30度的话等于1/2
                var left = opt.rect.offsetLeft;
                var top = opt.rect.offsetTop;
                if(opt.radian>0){
					if(lft){
						left+=opt.step;
						opt.radian-=1;
						var a = left - opt.initLeft;
						var c = (a/cos);
						var b = (sin*c);
					}else{
						left-=opt.step;
						opt.radian-=1;
						var a = left - opt.initLeft;
						var c = -(a/cos);
						var b = (sin*c);
					}
                    opt.rect.style.left = opt.initLeft+a+"px";
                    opt.rect.style.top = opt.initTop-b+"px";
                    setTimeout(function(){
                        animate(opt);
                    },10);
                }else{
                    opt.rect.style.left = left+opt.step+"px";
                    opt.rect.style.top = opt.initTop+"px";
                    opt.step && animate({
                        step : --opt.step,
                        g : 1,
                        rect : opt.rect,
                        radian : opt.radian,
                        initTop : opt.rect.offsetTop,
                        initLeft : opt.rect.offsetLeft
                    });
                }
            }
            animate({
                step : step,
                g : 1,
                rect : rect,
                radian : radian,
                initTop : rect.offsetTop,
                initLeft : rect.offsetLeft
            });
        }
function wheel(thdown,fast,t,msg,selec,oid,giftid){
	var th=0,fast=fast,tst=thdown;
	if(wheels){clearInterval(wheels);}
	if(!thdown){thdown=360*RandomNum(2,4);}
	if(KISSY.UA.shell=="ie"){
		// IE动画
		$(".action_flash_wheel_flash_gift").addClass("hide");
		$(".action_flash_wheel_flash_slow").addClass("hide");
		$(".action_flash_wheel_flash_quick").removeClass("hide");
	}	
	wheels=setInterval(function (){
		var degree = th/fast;
		th++;
		if(degree && degree+1>=(thdown*Math.PI)/180){
			if(KISSY.UA.shell=="ie"){
				$(".action_flash_wheel_flash_quick").addClass("hide");
				$(".action_flash_wheel_flash_"+(thdown%360)).removeClass("hide");
			}else{
				// 直接定位到指定位置并停止旋转
				wheel_run((thdown*Math.PI)/180);//以matrix旋转
				// run(degree);  //以rotate旋转
			}
			gameDialog(t,msg,selec,oid,false,top);
			clearInterval(wheels);
		}else{
			wheel_run(degree);
		}
	},30);
}

function wheel_run(degree){
	var a,b,c,d,e,f;
	a = Math.cos(degree).toFixed(6);
	b = Math.sin(degree).toFixed(6);
	c = -(Math.sin(degree)).toFixed(6);
	d = Math.cos(degree).toFixed(6);
	e = 0;
	f = 0;
	// $(".wheels_ac").css("-moz-transform","rotate("+degree+"deg)");
	// $(".wheels_ac").css("-webkit-transform","rotate("+degree+"deg)");
	// $(".wheels_ac").css("-o-transform","rotate("+degree+"deg)");
	// $(".wheels_ac").css("-ms-transform","rotate("+degree+"deg)");
	// $(".wheels_ac").css("-moz-transform","matrix("+a+", "+b+", "+c+", "+d+", "+e+", "+f+")");
	// $(".wheels_ac").css("-webkit-transform","matrix("+a+", "+b+", "+c+", "+d+", "+e+", "+f+")");
	// $(".wheels_ac").css("-o-transform","matrix("+a+", "+b+", "+c+", "+d+", "+e+", "+f+")");
	// $(".wheels_ac").css("-ms-transform","matrix("+a+", "+b+", "+c+", "+d+", "+e+", "+f+")");
	$(".wheels_ac").css("transform","matrix("+a+", "+b+", "+c+", "+d+", "+e+", "+f+")");
}
function showmygift(pg){
pg=pg?pg:0;
var sid = $(".sid").val();
KISSY.io({
		url: "/?m=shopmodule&c=user",
		data: {"usernick":usernick,"page":pg,"shop_id":sid},
		success: function(data) {
		$(".js-gmdlg").remove();
			var msg="<div style=\"overflow: auto;height: 180px;\">";
				msg+=("<table class=\"table\">");
				msg+=("        <thead>");
				msg+=("          <tr>");
				msg+=("            <th></th>");
				msg+=("            <th>名称</th>");
				msg+=("            <th width=\"50\">价值</th>");
				msg+=("            <th>领奖信息</th>");
				msg+=("          </tr>");
				msg+=("        </thead>");
				msg+=("        <tbody>");
			for(var i in data.data){
				msg+=("          <tr>");
				msg+=("            <td></td>");
				msg+=("            <td><a href=\""+data.data[i].num_iids+"\"><div style=\"float:left\">"+data.data[i].name+"</div><div style=\"float:left;background:url(http://a.tbcdn.cn/tbsp/img/header/header_bg_20100225.png) 0 -60px ;width:13px;height:13px\"></div></a></td>");
				msg+=("            <td>"+data.data[i].price+"</td>");
				var datatp = data.data[i].type;
				// if(data.data[i].type==1){
					// msg+="<td>";
					// if(data.data[i].wlid){
						// msg+=("["+data.data[i].wlcode+"] 单号："+data.data[i].wlid);
					// }else{
						// msg+=("尚未发奖");
					// }
					// msg+="<br />亲，您获得了实物奖。请联系客服留下您的收货方式，客服会为您直接邮寄奖品哦！";
					// msg+="</td>";
				// }else{
					msg+="<td>";
					switch(parseInt(datatp)){
						case 1:
						if(data.data[i].wlid){
							msg+=("["+data.data[i].wlcode+"] 单号："+data.data[i].wlid);
						}else{
							msg+=("尚未发奖");
						}
						msg+="<br />亲，您获得了实物奖。请联系客服留下您的收货方式，客服会为您直接邮寄奖品哦！";
						break;
						case 5:
						msg+="<a href=\""+data.data[i].num_iids+"\">"+data.data[i].num_iids+"</a>";
						msg+="<br />亲，您获得了折扣奖品。请打开目标商品查看折扣，超过领奖时间折扣会消失哦！";
						break;
						case 4:
						msg+="卡号：【"+data.data[i].cardno+"】密码：【"+data.data[i].secret+"】";
						msg+="<br />亲，您获得了卡密！请查看兑奖方式，超过领奖时间卡密会失效哦！";
						break;
						default:
						msg+="<a href=\""+data.data[i].num_iids+"\">"+data.data[i].num_iids+"</a>";
						break;
					}
					msg+="</td>";
				// }
				msg+=("          </tr>");
			}
				msg+=("        </tbody>");
				msg+=("    </table>");
				msg+=("<div class=\"pagination\" style=\"text-align:center\">");
				msg+=("        <ul>");
			var style=(pg==0||data.count==0)?"disabled":"";
				msg+=("          <li class=\""+style+" js-foward\" ><a href=\"#\">« 上一页</a></li>");
				msg+=("          ");
				msg+=("          ");
				msg+=("          ");
				msg+=("          ");
			var style=(pg*7>=data.count)?"disabled":"";
				msg+=("          <li class=\"js-next "+style+"\"><a href=\"#\">下一页 »</a></li>");
				msg+=("          <li><a href=\"#\" class=\"js-ok button\" style=\"color:#FF2D68\">关闭</a></li>");
				msg+=("        </ul>");
				msg+=("      </div></div>");
			gameDialog("您的奖品",msg,"event",false,900,50);
			$(".btn btn-mini").remove();
			if(pg*7<data.count){
				$(".js-next").on("click",function(){
					showmygift(usernick,++pg);
				});
			}
			if(pg>0){
			$(".js-foward").on("click",function(){
				showmygift(usernick,--pg);
			});
			}
		},
		error: function(){alert('出错啦！请仔细检查一下输入的数据是否有误！');},
		"dataType":"jsonp"
		});
}

// KISSY.use("anim", function(S, Anim)
// {
var b = new KISSY.Anim('.winlist',{scrollTop: 0}, 5 ,'',function(){t.run();});
var t = new KISSY.Anim('.winlist',{scrollTop: 100}, 5 ,'',function(){b.run();});
t.run();

//刮刮卡换一张
// var cisrun=false;
// $(".scratchcards_ac").on("click",function(){
	// $(".gua1").css("width","130px");
	// $(".gua").css("width","130px");
	// if(!cisrun){
		// $(".js-card1").css("left","398px");
		// $(".js-card1").css("display","block");
		// $(".js-card2").css("display","block");
		// var e = new KISSY.Anim('.js-card2',{"left": 398}, 1 ,'easeBothStrong',function(){
					// $(".js-card1").css("display","block");
					// $(".js-card2").css("display","none");
					// $(".gua").css("width","130px");
					// cisrun = false;
					// });
		// var d = new KISSY.Anim('.js-card1',{"left": 258}, 1 ,'easeBothStrong',function(){$(".js-card1").css("display","none");});
		// cisrun = true;
		// d.run();
		// e.run();
	// }
// });
var isrun;
$(".scratchcards_ac").on("click",function(){
	$(".gua1").css("width","130px");
	if(!isrun){
		$(".js-card1").css("left","398px");
		$(".js-card1").css("-moz-opacity","1");
		$(".js-card1").css("opacity","1");
		$(".js-card1").css("filter","alpha(opacity=100)");
		$(".js-card1").css("display","display");
		$(".js-card2").css("display","block");
		var e = new KISSY.Anim('.js-card2',{"left": 398,"-moz-opacity":1,"opacity":1,"filter":"alpha(opacity=100)"}, 1 ,'easeBothStrong',function(){
					$(".js-card1").css("left","398px");
					$(".js-card1").css("-moz-opacity","1");
					$(".js-card1").css("opacity","1");
					$(".js-card1").css("filter","alpha(opacity=100)");
					$(".js-card1").css("display","block");
					$(".js-card2").css("left","530px");
					$(".js-card2").css("-moz-opacity","0");
					$(".js-card2").css("opacity","0");
					$(".js-card2").css("filter","alpha(opacity=0)");
					$(".js-card2").css("display","none");
					$(".gua").css("width","130px");
					isrun = false;
					});
		var d = new KISSY.Anim('.js-card1',{"left": 258,"-moz-opacity":0,"opacity":0,"filter":"alpha(opacity=0)"}, 1 ,'easeBothStrong',function(){$(".js-card1").css("display","none");});
		isrun = true;
		d.run();
		e.run();
	}
});
// 水果机自动
/*
var s = new KISSY.Anim('.js-fruit1',{"top": 0}, 3 ,'',function(){
		$(".js-fruit1").css("top","-82px");
		s.run();
	});
	s.run();
var s1 = new KISSY.Anim('.js-fruit2',{"top": 0}, 3 ,'',function(){
		$(".js-fruit2").css("top","-82px");
		s1.run();
	});
	s1.run();
var s2 = new KISSY.Anim('.js-fruit3',{"top": 0}, 3 ,'',function(){
		$(".js-fruit3").css("top","-82px");
		s2.run();
	});
	s2.run();
*/	
function RandomNum(Min,Max){
	var Range = Max - Min;
	var Rand = Math.random();   
	var num = (parseInt(Math.round(Rand * Range))+parseInt(Min));
	return num;
}
function qiandaorili(curdate){
	var calUtil = {
		getDaysInmonth : function(iMonth, iYear){
		  var dPrevDate = new Date(iYear, iMonth, 0);
		  return dPrevDate.getDate();
		},
		bulidCal : function(iYear, iMonth) {
		  var aMonth = new Array();
		  aMonth[0] = new Array(7);
		  aMonth[1] = new Array(7);
		  aMonth[2] = new Array(7);
		  aMonth[3] = new Array(7);
		  aMonth[4] = new Array(7);
		  aMonth[5] = new Array(7);
		  aMonth[6] = new Array(7);
		  var dCalDate = new Date(iYear, iMonth - 1, 1);
		  var iDayOfFirst = dCalDate.getDay();
		  var iDaysInMonth = calUtil.getDaysInmonth(iMonth, iYear);
		  var iVarDate = 1;
		  var d, w;
		  aMonth[0][0] = "日";
		  aMonth[0][1] = "一";
		  aMonth[0][2] = "二";
		  aMonth[0][3] = "三";
		  aMonth[0][4] = "四";
		  aMonth[0][5] = "五";
		  aMonth[0][6] = "六";
		  for (d = iDayOfFirst; d < 7; d++) {
			aMonth[1][d] = iVarDate;
			iVarDate++;
		  }
		  for (w = 2; w < 7; w++) {
			for (d = 0; d < 7; d++) {
			  if (iVarDate <= iDaysInMonth) {
				aMonth[w][d] = iVarDate;
				iVarDate++;
			  }
			}
		  }
		  return aMonth;
		},
		ifHasSigned : function(signList,day){
		  var signed = new Array();
		  for(var i=0;i<signList.length;i++){
			  if(signList[i].signDay==day){
				  signed["type"]= signList[i].signType;
				  signed["giftid"]= signList[i].giftId;
				  switch(signList[i].giftDay){
					  case 1 : signed["giftcss"] = " giftok "; break;
					  case 2 : signed["giftcss"] = " gift "; break;
				  }
			  }
		  }
		  return signed ;
		},
		drawCal : function(iYear, iMonth ,signList) {
		  var myMonth = calUtil.bulidCal(iYear, iMonth);
		  var htmls = new Array();
		  var mon = iMonth>=10?iMonth:"0"+iMonth;
		  htmls.push("<div class='sign_main' id='sign_layer'>");
		  htmls.push("<div class='sign_succ_calendar_title'>");
		  htmls.push("<div class='calendar_month_next js-changmon' data-mon=\""+getNextMonth(iYear+"-"+mon+"-"+"01")+"\"></div>");
		  htmls.push("<div class='calendar_month_prev js-changmon' data-mon=\""+getPreMonth(iYear+"-"+mon+"-"+"01")+"\"></div>");
		  htmls.push("<div class='calendar_month_span'>"+iYear+"年"+iMonth+"月</div>");
		  htmls.push("<span class=\"ks-ext-close-x js-close-cal\">关闭</span>");
		  htmls.push("</div>");
		  htmls.push("<div class='sign' id='sign_cal'>");
		  htmls.push("<table>");
		  htmls.push("<tr>");
		  htmls.push("<th>" + myMonth[0][0] + "</th>");
		  htmls.push("<th>" + myMonth[0][1] + "</th>");
		  htmls.push("<th>" + myMonth[0][2] + "</th>");
		  htmls.push("<th>" + myMonth[0][3] + "</th>");
		  htmls.push("<th>" + myMonth[0][4] + "</th>");
		  htmls.push("<th>" + myMonth[0][5] + "</th>");
		  htmls.push("<th>" + myMonth[0][6] + "</th>");
		  htmls.push("</tr>");
		  var d, w;
		  for (w = 1; w < 7; w++) {
			htmls.push("<tr>");
			for (d = 0; d < 7; d++) {
			  var day = myMonth[w][d]>=10?myMonth[w][d]:"0"+myMonth[w][d];
			  var ifHasSigned = calUtil.ifHasSigned(signList,myMonth[w][d]);
			  var giftDayCss = ifHasSigned.giftcss?ifHasSigned.giftcss:"";
			  var giftId = ifHasSigned.giftid?" data-gid=\""+ifHasSigned.giftid+"\" data-date=\""+iYear+"-"+iMonth+"-"+myMonth[w][d]+"\"":"";
			  console.log(ifHasSigned);
			  if(ifHasSigned.type==1){
				giftDayCss=giftDayCss?giftDayCss:"on";
				htmls.push("<td class='"+giftDayCss+"' "+giftId+">" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");
			  }else if(ifHasSigned.type==2){ //允许补签
				htmls.push("<td class='"+giftDayCss+"' "+giftId+"><input data-tp=\"buqian\" data-day=\""+iYear+"-"+mon+"-"+day+"\" class=\"btn btn-mini btn-primary js-buqian\" type=\"button\" value=\"补签\"></td>");
			  }else if(ifHasSigned.type==3){ //允许领奖
				htmls.push("<td class='"+giftDayCss+"'  "+giftId+"><input data-tp=\"lingjiang\" data-day=\""+iYear+"-"+mon+"-"+day+"\" class=\"btn btn-mini btn-warning js-buqian\" type=\"button\" value=\"领奖\"></td>");
			  }else if(ifHasSigned.type==4){ //已经补签
				giftDayCss=giftDayCss?giftDayCss:"on_bu";
				htmls.push("<td class='"+giftDayCss+"' "+giftId+">" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");
			  }else if(ifHasSigned.type==5){ //不在本月
				htmls.push("<td class=\"on_la\">" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");
			  }else if(ifHasSigned.type==6){ //允许签到
				htmls.push("<td class='"+giftDayCss+"' "+giftId+"><input class=\"btn btn-mini js-calqd\" type=\"button\" value=\"签到\"></td>");
			  }else if(ifHasSigned.type==7){ //等待奖品
				htmls.push("<td class=\"gift\">" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");
			  }else {
				htmls.push("<td class='"+giftDayCss+"' "+giftId+">" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");
			  }
			}
			htmls.push("</tr>");
		  }
		  htmls.push("</table>");
		  htmls.push("</div>");
		  htmls.push("</div>");
		  return htmls.join('');
		}
	};
	KISSY.io({
			"url": "/?a=qiandaorili&m=shopmodule&c=jifen",
			"data":{"usernick":usernick,"sid":sid,"curdate":curdate},
			"success": function(data, textStatus) {
				curdate = curdate?new Date(curdate):new Date();
				var signList = data.signlist;
				var str = calUtil.drawCal(curdate.getFullYear(),curdate.getMonth() + 1,signList);
				closeDialog();
				$(str).prependTo(".event");
				$(".js-close-cal").on("click",function(){
					$(".sign_main").remove();
				});
				$(".js-calqd").on("click",function(){
					$(".js-qiandao").fire("click");
				});
				$(".gift,.giftok").on("click",function(){
					var gid = $(this).attr("data-gid");
					var date = $(this).attr("data-date");
					var msg,btn="";
					if($(this).hasClass("giftok")){
						msg="亲，您可以领取奖品啦！";
						btn="<input  data-date=\"\" class=\"btn btn-mini btn-info js-qdlj\" type=\"button\" value=\"立即领奖\">";
					}else{
						msg="亲，加油连续签到可得奖品：";
					}
					var sign = R(usernick+"|"+sid+"|"+gid+"|"+"ntPfLBg"+ti);
					KISSY.io({
						"url": "/?a=showdaysdh&m=shopmodule&c=jifen",
						"data":{"usernick":usernick,"sid":sid,"sign":sign,"gids":gid,"ti":ti},
						"success": function(data, textStatus) {
							if(data.status){
								gameDialog("兑换奖品","<center>"+msg+"<br /><img src=\""+data.gift.pic_url+"_150x150.jpg\" style=\"width:150px;height:150px;\" /><br />"+data.gift.name+"<br />"+btn+"</center>","event",false,false,50);
								$(".js-ok").remove();
								$(".js-qdlj").on("click",function(){
									var sign = R(usernick+"|"+sid+"|"+gid+"|"+date+"|"+"ntPfLBg"+ti);
									KISSY.io({
										"url": "/?a=daysduih&m=shopmodule&c=jifen",
										"data":{"usernick":usernick,"sid":sid,"sign":sign,"gids":gid,"date":date,"ti":ti},
										"success": function(data, textStatus) {
											closeDialog();
											gameDialog("兑换奖品",data.msg,"event");
										},
										"error": function(){
											gameDialog("兑换奖品",'抱歉，通讯失败。刷新重试',"event");
										},
										"dataType":"jsonp"
									});
								});
							}else{
								gameDialog("兑换奖品",data.msg,"event");
							}
						},
						"error": function(){
							gameDialog("补签",'抱歉，通讯失败。刷新重试',"event");
						},
						"dataType":"jsonp"
					});
				});
				$(".js-changmon").on("click",function(){
					var mon = $(this).attr("data-mon");
					$(".js-close-cal").fire("click");
					qiandaorili(mon);
				});
				$(".js-buqian").on("click",function(){
					var day = $(this).attr("data-day");
					var tp = $(this).attr("data-tp");
					var sign = R(sid+"|"+day+"|"+usernick+"|"+"ntPfLBg"+ti);
					KISSY.io({
						"url": "/?a=buqian&m=shopmodule&c=jifen",
						"data":{"usernick":usernick,"sid":sid,"sign":sign,"curdate":day,"ti":ti},
						"success": function(data, textStatus) {
							gameDialog("补签",""+data.msg,"event");
							$(".js-dhdh").on("click",function(){
								$(".js-ddhjiafen").fire("click");
							});
							$(".js-ok").remove();
						},
						"error": function(){
							gameDialog("补签",'抱歉，通讯失败。刷新重试',"event");
						},
						"dataType":"jsonp"
					});
				});
			},
			"error": function(){
				gameDialog("购物车",'亲，距离您上次登录淘宝太久，请重新<a target=\"_blank\" class=\"btn btn-mini btn-warning js-cls \" href=\"http://trade.taobao.com/trade/itemlist/list_bought_items.htm\">登录</a>以后再来抽奖！',"event");
				$(".js-ok").remove();
			},
			"dataType":"jsonp"
		});
}
/**
         * 获取上一个月
         *
         * @date 格式为yyyy-mm-dd的日期，如：2014-01-25
         */
        function getPreMonth(date) {
            var arr = date.split('-');
            var year = arr[0]; //获取当前日期的年份
            var month = arr[1]; //获取当前日期的月份
            var day = arr[2]; //获取当前日期的日
            var days = new Date(year, month, 0);
            days = days.getDate(); //获取当前日期中月的天数
            var year2 = year;
            var month2 = parseInt(month) - 1;
            if (month2 == 0) {
                year2 = parseInt(year2) - 1;
                month2 = 12;
            }
            var day2 = day;
            var days2 = new Date(year2, month2, 0);
            days2 = days2.getDate();
            if (day2 > days2) {
                day2 = days2;
            }
            if (month2 < 10) {
                month2 = '0' + month2;
            }
            var t2 = year2 + '-' + month2 + '-' + day2;
            return t2;
        }
        
        /**
         * 获取下一个月
         *
         * @date 格式为yyyy-mm-dd的日期，如：2014-01-25
         */        
        function getNextMonth(date) {
            var arr = date.split('-');
            var year = arr[0]; //获取当前日期的年份
            var month = arr[1]; //获取当前日期的月份
            var day = arr[2]; //获取当前日期的日
            var days = new Date(year, month, 0);
            days = days.getDate(); //获取当前日期中的月的天数
            var year2 = year;
            var month2 = parseInt(month) + 1;
            if (month2 == 13) {
                year2 = parseInt(year2) + 1;
                month2 = 1;
            }
            var day2 = day;
            var days2 = new Date(year2, month2, 0);
            days2 = days2.getDate();
            if (day2 > days2) {
                day2 = days2;
            }
            if (month2 < 10) {
                month2 = '0' + month2;
            }
        
            var t2 = year2 + '-' + month2 + '-' + day2;
            return t2;
        }
// });
// });
